import 'package:cross_file/cross_file.dart';
import 'package:desktop_drop/desktop_drop.dart';
import 'package:excel_utils/extend/string_extend.dart';
import 'package:excel_utils/pages/view/calendar_view.dart';
import 'package:excel_utils/pages/week/bean/CustomerAdditionBean.dart';
import 'package:excel_utils/pages/week/bean/OtherOnlineRetailersBean.dart';
import 'package:excel_utils/pages/week/week_entry/child/quotation_record/quotation_record_page.dart';
import 'package:excel_utils/pages/week/week_entry/week_entry_page.dart';
import 'package:excel_utils/repository/k8/k8_repository.dart';
import 'package:excel_utils/widgets/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../daily/daily_report/bean/CmcTicketBean.dart';
import '../../daily/daily_report/bean/DailyInformationBean.dart';
import '../../daily/daily_report/bean/DailyVoteBean.dart';
import '../../daily/daily_report/bean/IndependentStatisticalBean.dart';
import '../../daily/daily_report/bean/LocalDeliveryStatisticsBean.dart';
import '../../daily/daily_report/bean/SignStatisticsBean.dart';
import '../../daily/daily_report/bean/ThirdPartyBean.dart';
import '../bean/AccountsReceivableBean.dart';
import '../bean/AdjustInvoiceBean.dart';
import '../bean/WaiPanZhanBiBean.dart';
import '../week_entry/child/week_data_entry/week_data_entry_page.dart';
import 'bloc/week_report_bloc.dart';

class WeekReportPage extends StatefulWidget {
  const WeekReportPage({super.key});

  @override
  State<WeekReportPage> createState() => _WeekReportPageState();
}

class _WeekReportPageState extends State<WeekReportPage> {
  WeekReportBloc? _weekReportBloc;

  bool dianShangLoading = false;
  Map<String, Map<String, dynamic>> resultDianShangMaps = {};
  List<SignStatisticsBean> dianShangCurrentData = [];
  List<SignStatisticsBean> dianShangLastData = [];
  // 电商
  String dianShangStartDate = "";
  String dianShangEndDate = "";

  // RINCOS
  bool rINCOSLoading = false;
  String accountNoStr = "";
  List<String> accountNo = [
    "98181001",
    "98181001A",
  ];
  Map<String, List<AccountData>> rINCOSData = {};

  Map<String, String> mapsFail = {};
  String rINCOSStartDate = "";
  String rINCOSEndDate = "";

  // 月费，套票解析
  List<CustomerBeanData> originDataTemp = [];
  List<CustomerBeanData> cDataTemp = [];
  List<CustomerBeanData> nDataTemp = [];
  List<CustomerBeanData> bDataTemp = [];
  bool _monthStopDragging = false;
  final List<XFile> _monthStopFile = [];

  // 套票銷售及使用
  String waybillPrintingStart = "";
  String waybillPrintingEnd = "";
  bool taoPiaoXiaoShouShiYongLoading = false;
  dynamic resultData;
  DailyInformationBean? dailyInformationBean;
  DailyVoteBean? dailyVoteBean;

  // 外判佔比.
  bool waiPanZhanBiLoading = false;
  ThirdPartyBean? thirdPartyBean;
  CmsTicketBean? cmsTicketBean;
  WaiPanZhanBiBean? waiPanZhanBiData;
  LocalDeliveryStatisticsBean? localDeliveryStatisticsBean;
  IndependentStatisticalBean? independentStatisticalBean;
  String waiPanZhanBiStartDate = "";
  String waiPanZhanBiEndDate = "";

  // 新电商比较
  bool newDianShangLoading = false;
  List<int> monthCounts = [];
  List<OtherOnlineData> existenceData = [];
  List<OtherOnlineData> nData = [];

  // 汇总表数据
  bool summaryDataLoading = false;

  Map<String, dynamic> tpData = {};
  Map<String, dynamic> monthData = {};
  List<Map<String, dynamic>> huizongRresultData = [];
  String huizongStartDate = "";
  String huizongEndDate = "";

  // 新电商比较
  final FocusNode _newOldDianShangFocusNode = FocusNode(debugLabel: 'Menu Button');
  String newDianShangStartDate = "";
  String newDianShangEndDate = "";
  String selectMonth = "";

  // MonthFeeAndTaoPiaoEvent  月费、套票客户解析
  String monthFeeStartDate = "";
  String monthFeeEndDate = "";

  // 调整审核数据  审核类型
  final FocusNode _auditTypeFocusNode = FocusNode(debugLabel: 'auditType');
  final FocusNode _auditStateFocusNode = FocusNode(debugLabel: 'auditState');
  bool adjustAuditLoading = false;
  dynamic auditType = ["全部", "全部"];
  dynamic auditState = ["全部", "全部"];
  String adjustAuditStartDate = "";
  String adjustAuditEndDate = "";
  Map<String, dynamic> adjustAuditData = {};
  Map<String, dynamic> resultWholeMonthData = {};

  // 时间范围
  int year = 0000;
  int month = 00;
  int day = 00;
  int hour = 00;
  int minute = 00;
  int second = 00;

  @override
  void initState() {
    DateTime now = DateTime.now();
    if (now.day == 1) {
      now = now.subtract(Duration(days: 1));
    }
    year = now.year;
    month = now.month;
    day = now.day;
    hour = now.hour;
    minute = now.minute;
    second = now.second;

    dianShangStartDate = "${year}-${month.toString().padLeft(2, '0')}-${(1).toString().padLeft(2, '0')} 00:00:00";
    dianShangEndDate = "${year}-${month.toString().padLeft(2, '0')}-${(day - 1).toString().padLeft(2, '0')} 23:59:59";

    waiPanZhanBiStartDate = "${year}-${month.toString().padLeft(2, '0')}-01 00:00:00";
    waiPanZhanBiEndDate = "${year}-${month.toString().padLeft(2, '0')}-${(day - 1).toString().padLeft(2, '0')} 23:59:59";

    waybillPrintingStart = "${year}-${month.toString().padLeft(2, '0')}-01 00:00:00";
    waybillPrintingEnd = "${year}-${month.toString().padLeft(2, '0')}-${(day - 1).toString().padLeft(2, '0')} 23:59:59";

    // 日期会退7天
    var subtract7 = DateTime.parse("${year}-${month.toString().padLeft(2, '0')}-${(day).toString().padLeft(2, '0')} 00:00:00").subtract(Duration(days: 7));
    huizongStartDate = "${subtract7.year}-${subtract7.month.toString().padLeft(2, '0')}-${(subtract7.day).toString().padLeft(2, '0')} 00:00:00";
    huizongEndDate = "${year}-${month.toString().padLeft(2, '0')}-${(day - 1).toString().padLeft(2, '0')} 23:59:59";

    // 新电商日期
    newDianShangStartDate = "${year}-${month.toString().padLeft(2, '0')}-${(1).toString().padLeft(2, '0')} 00:00:00";
    newDianShangEndDate = "${year}-${month.toString().padLeft(2, '0')}-${(day - 1).toString().padLeft(2, '0')} 23:59:59";

    var subtractMonthFee =
        DateTime.parse("${year}-${month.toString().padLeft(2, '0')}-${(day).toString().padLeft(2, '0')} 00:00:00").subtract(Duration(days: 7));
    monthFeeStartDate = "${subtract7.year}-${subtract7.month.toString().padLeft(2, '0')}-${(subtract7.day).toString().padLeft(2, '0')}";
    monthFeeEndDate = "${year}-${month.toString().padLeft(2, '0')}-${(day - 1).toString().padLeft(2, '0')}";

    adjustAuditStartDate = "${subtract7.year}-${subtract7.month.toString().padLeft(2, '0')}-${(subtract7.day).toString().padLeft(2, '0')}";
    adjustAuditEndDate = "${year}-${month.toString().padLeft(2, '0')}-${(day).toString().padLeft(2, '0')}";

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: BlocProvider<WeekReportBloc>(
          create: (context) => WeekReportBloc(context.read<K8Repository>()),
          child: BlocBuilder<WeekReportBloc, WeekReportState>(
            builder: (BuildContext context, WeekReportState state) {
              _weekReportBloc = _weekReportBloc ?? BlocProvider.of<WeekReportBloc>(context);
              if (state is Table1LoadingState) {
              } else if (state is DianShangLoadingState) {
                dianShangLoading = true;
                dianShangCurrentData.clear();
                dianShangLastData.clear();
                resultDianShangMaps.clear();
              } else if (state is DianShangState) {
                dianShangCurrentData = state.currentData;
                dianShangLastData = state.lastMonthData;
                resultDianShangMaps = state.resultMaps;
                dianShangLoading = false;
              } else if (state is RincosLoadingState) {
                rINCOSLoading = true;
              } else if (state is RincosResultState) {
                rINCOSData = state.resultData;
                mapsFail = state.mapsFail;
                rINCOSLoading = false;
              } else if (state is WaiPanZhanBiLoadingState) {
                waiPanZhanBiLoading = true;
                waiPanZhanBiData = null;
                localDeliveryStatisticsBean = null;
                independentStatisticalBean = null;
                thirdPartyBean = null;
                cmsTicketBean = null;
              } else if (state is WaiPanZhanBiSuccessState) {
                waiPanZhanBiLoading = false;
                thirdPartyBean = state.thirdPartyBean;
                cmsTicketBean = state.cmsTicketBean;
                waiPanZhanBiData = state.waiPanZhanBiBean;
                localDeliveryStatisticsBean = state.localDeliveryStatisticsBean;
                independentStatisticalBean = state.independentStatisticalBean;
              } else if (state is TaoPiaoXiaoShouShiYongLoadingState) {
                taoPiaoXiaoShouShiYongLoading = true;
                resultData = null;
                dailyInformationBean = null;
                dailyVoteBean = null;
              } else if (state is TaoPiaoXiaoShouShiYongSuccessState) {
                taoPiaoXiaoShouShiYongLoading = false;
                resultData = state.resultData;
                dailyInformationBean = state.dailyInformationBean;
                dailyVoteBean = state.dailyVoteBean;
              } else if (state is MonthFeeAndTaoPiaoSuccessState) {
                originDataTemp = state.originDataTemp;
                cDataTemp = state.cDataTemp;
                nDataTemp = state.nDataTemp;
                bDataTemp = state.bDataTemp;
              } else if (state is DianShangDataLoadingState) {
                newDianShangLoading = true;
              } else if (state is DianShangDataSuccessState) {
                newDianShangLoading = false;
                monthCounts = state.monthCounts;
                existenceData = state.existenceData;
                nData = state.nData;
              } else if (state is HuiZongDataLoadingState) {
                summaryDataLoading = true;
                huizongRresultData.clear();
                tpData.clear();
                monthData.clear();
              } else if (state is HuiZongDataSuccessState) {
                summaryDataLoading = false;
                huizongRresultData = state.resultData;
                tpData = state.tpData;
                monthData = state.monthData;
              } else if (state is AdjustmentAuditLoadingState) {
                adjustAuditLoading = true;
              } else if (state is AdjustmentAuditSuccessState) {
                adjustAuditLoading = false;
                adjustAuditData = state.resultAllData;
                resultWholeMonthData = state.resultWholeMonthData;
              }
              return _buildUI(context: context);
            },
          )),
      floatingActionButton: FloatingActionButton(
        onPressed: () {},
        child: BackButton(),
      ),
    );
  }

  Widget _buildUI({required BuildContext context}) {
    return SingleChildScrollView(
      child: Container(
          child: Column(
        children: [
          Row(
            children: [
              Text("周报表"),
            ],
          ),

          Container(
            margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
            child: Row(
              children: [
                ElevatedButton(
                    onPressed: () {
                      Navigator.push(context, MaterialPageRoute(builder: (_) => WeekEntryPage()));
                    },
                    child: Text("数据录入")),
              ],
            ),
          ),

          // 电商
          _buildDianShangWidget(),

          // 集运
          _buildRINCOSWidget(),

          //月费，套票解析
          _buildMonthFeeAndTaoPiaoWidget(),

          // 套票销售及使用
          _buildTaoPiaoXiaoShouShiYongWidget(),

          // 外判佔比
          _buildWaiPanZhanBiWidget(),

          // 新电商比较
          _buildNewDianShangWidget(),

          // 汇总表数据
          _buildSummaryDataWidget(),

          // 客服记录
          QuotationRecordPage(),

          // 调整审核
          _buildAdjustmentAuditWidget(),
        ],
      )),
    );
  }

  Set<String> dianShangCode = {"98181001", "98181001A", "9821015", "9821156", "9821164", "9821080", "9823036", "9821047"};
  String dianShangStr = '98181001,98181001A,9821015,9821156,9821164,9821080,9823036,9821047';
  // 是否查询上个月
  bool isQueryLastMonth = false;

  _buildDianShangWidget() {
    return Container(
      decoration: BoxDecoration(border: Border.all(color: Colors.pinkAccent, width: 3)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Column(
            children: [
              dianShangLoading
                  ? CircularProgressIndicator()
                  : Row(
                      children: [
                        ElevatedButton(
                          onPressed: () {
                            if (dianShangStr.isNotEmpty) {
                              // dianShangStr 通过、分割，转成数组
                              List<String> dianShangMaps = dianShangStr.split(",");
                              dianShangCode.clear();
                              dianShangCode.addAll(dianShangMaps);
                            }
                            _weekReportBloc?.add(DianShangEvent(
                              dianShangMaps: dianShangCode.toList(),
                              // dianShangMaps: ["98181001", "98181001A", "9821015", "9825001", "9821164", "9821080", "9823036", "9821047"],
                              startDate: '$dianShangStartDate',
                              endDate: '$dianShangEndDate',
                              blGrouping: 1,
                              isQueryLastMonth: isQueryLastMonth,
                            ));
                          },
                          child: Text("电商 获取数据"),
                        ),
                        SizedBox(width: 10),
                        Text("是否查询上个月"),
                        Checkbox(
                          value: isQueryLastMonth,
                          onChanged: (value) {
                            isQueryLastMonth = value!;
                            setState(() {});
                          },
                        ),
                      ],
                    ),
              TextField(
                controller: TextEditingController(text: dianShangStr),
                onChanged: (value) {
                  dianShangStr = value;
                },
              ),
              CalendarView(
                day: 1,
                onInitDateChanged: (startDateTime, startStr, endDateTime, endStr) {
                  dianShangStartDate = "${startStr}";
                  dianShangEndDate = "${endStr}";
                },
                onDateStartChanged: (startDateTime, startStr) {
                  print("disMonthFeeStartDate: $startDateTime, $startStr");
                  dianShangStartDate = "${startStr}";
                },
                onDateEndChanged: (endDateTime, endStr) {
                  print("disMonthFeeEndDate: $endDateTime, $endStr");
                  dianShangEndDate = "${endStr}";
                },
              ),
            ],
          ),
          Row(
            children: [
              if (resultDianShangMaps.isNotEmpty)
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    ...resultDianShangMaps.entries.map((entry) {
                      String lastMonthCount = "";
                      String lastMonthgROUPDATE = "";
                      String lastMonthString = "";
                      String input = "";
                      if (entry.value["lastMonth"] != null) {
                        lastMonthCount = entry.value["lastMonth"]!.single.cOUNT.toString();
                        lastMonthgROUPDATE = entry.value["lastMonth"]!.single.gROUPDATE.toString();
                        lastMonthString = "${lastMonthgROUPDATE.substring(5, 7)}月份(${lastMonthCount})票";
                        input = entry.value["lastMonth"]!.single.sIXCOUNT.toString(); //
                      }
                      // String lastMonthCount = entry.value["lastMonth"]!.single.cOUNT.toString();
                      // String lastMonthgROUPDATE = entry.value["lastMonth"]!.single.gROUPDATE.toString();
                      // String lastMonthString = "${lastMonthgROUPDATE.substring(5, 7)}月份(${lastMonthCount})票";
                      // String input = entry.value["lastMonth"]!.single.sIXCOUNT.toString(); //
                      dynamic lastPercentage;
                      try {
                        lastPercentage = input.substring(input.indexOf("(") + 1, input.indexOf(")"));
                      } catch (e) {
                        lastPercentage = "0.00";
                      }

                      String currentMonthCount = entry.value["currentMonth"]!.single.cOUNT.toString();
                      String currentMonthgROUPDATE = entry.value["currentMonth"]!.single.gROUPDATE.toString();
                      String currentMonthString = "${currentMonthgROUPDATE.substring(5, 7)}月份(${currentMonthCount})票";
                      String input2 = entry.value["currentMonth"]!.single.sIXCOUNT.toString(); //
                      dynamic currentPercentage;
                      try {
                        currentPercentage = input2.substring(input2.indexOf("(") + 1, input2.indexOf(")"));
                      } catch (e) {
                        currentPercentage = "0.00";
                      }
                      return Container(
                        decoration: BoxDecoration(border: Border.all(color: Colors.blue, width: 1)),
                        padding: const EdgeInsets.all(8.0),
                        child: Row(
                          children: [
                            // 编号
                            Text(entry.key),
                            SizedBox(width: 30),
                            InkWell(
                              onTap: () {
                                "$lastMonthString\n$currentMonthString".copyValue();
                              },
                              child: Column(
                                children: [
                                  // 上个月
                                  Text(lastMonthString, style: TextStyle(color: Colors.red)),
                                  // 当月
                                  Text(currentMonthString, style: TextStyle(color: Colors.red)),
                                ],
                              ),
                            ),
                            SizedBox(width: 30),
                            InkWell(
                              onTap: () {
                                dynamic percentage1 = lastPercentage;
                                try {
                                  percentage1 = percentage1.replaceAll("%", "");
                                  percentage1 = double.parse(percentage1).toStringAsFixed(1);
                                  // 再 / 100
                                  percentage1 = (double.parse(percentage1) / 100);
                                  percentage1.toString().copyValue();
                                } catch (e) {
                                  // 99.77%
                                  percentage1 = "0.0";
                                  percentage1.toString().copyValue();
                                }

                                dynamic percentage2 = currentPercentage;
                                try {
                                  percentage2 = percentage2.replaceAll("%", "");
                                  percentage2 = double.parse(percentage2).toStringAsFixed(1);
                                  // 再 / 100
                                  percentage2 = (double.parse(percentage2) / 100);
                                  percentage2.toString().copyValue();
                                } catch (e) {
                                  // 99.77%
                                  percentage2 = "0.0";
                                  percentage2.toString().copyValue();
                                }
                                //日期
                                String currentMonthEnd = currentMonthgROUPDATE.substring(16, 21);
                                String currentMonthTip = "(以${currentMonthEnd.substring(0, 2)}/${currentMonthEnd.substring(3, 5)}计算)";
                                "$percentage1\n$percentage2\n$currentMonthTip".copyValue();
                              },
                              child: Column(
                                children: [
                                  // 上个月
                                  Text(lastPercentage.toString()),
                                  // 当月
                                  Text(currentPercentage.toString()),
                                ],
                              ),
                            ),
                          ],
                        ),
                      );
                    }),
                  ],
                ),
              // if (dianShangLastData.isNotEmpty)
              //   Column(
              //     crossAxisAlignment: CrossAxisAlignment.start,
              //     children: [
              //       ...dianShangLastData.map((item) {
              //         String input = item.data!.single.sIXCOUNT.toString(); //
              //         // 匹配到数字后，取出数字
              //         dynamic percentage;
              //         try {
              //           percentage = input.substring(input.indexOf("(") + 1, input.indexOf(")"));
              //         } catch (e) {
              //           percentage = "0.00";
              //         }
              //         //COUNT
              //          String count = item.data!.single.cOUNT.toString();
              //          String gROUPDATE = item.data!.single.gROUPDATE.toString();
              //         // 取出月份
              //         String month = "${gROUPDATE.substring(5, 7)}月份(${count})票";
              //
              //         return Row(
              //           children: [
              //             Text("${gROUPDATE}       "),
              //             SizedBox(width: 10),
              //             Text("${item.reqCode?["empCode"]}-----"),
              //             InkWell(
              //               onTap: () {
              //                 "${month}月份(${count})票".copyValue();
              //               },
              //               child: Text(
              //                 "${month}月份(${count})票",
              //                 style: TextStyle(color: Colors.blue),
              //               ),
              //             ),
              //             SizedBox(width: 20),
              //             InkWell(
              //               onTap: () {
              //                 dynamic percentage;
              //                 try {
              //                   percentage = input.substring(input.indexOf("(") + 1, input.indexOf(")"));
              //                 } catch (e) {
              //                   percentage = "0.00";
              //                 }
              //                 try {
              //                   percentage = percentage.replaceAll("%", "");
              //                   percentage = double.parse(percentage).toStringAsFixed(1);
              //                   // 再 / 100
              //                   percentage = (double.parse(percentage) / 100);
              //                   percentage.toString().copyValue();
              //                 } catch (e) {
              //                   // 99.77%
              //                   percentage = "0.0";
              //                   percentage.toString().copyValue();
              //                 }
              //               },
              //               child: Text(
              //                 "${percentage}",
              //                 style: TextStyle(color: Colors.blue),
              //               ),
              //             )
              //           ],
              //         );
              //       }),
              //     ],
              //   ),
              // Spacer(),
              // if (dianShangCurrentData.isNotEmpty)
              //   Column(
              //     crossAxisAlignment: CrossAxisAlignment.start,
              //     children: [
              //       ...dianShangCurrentData.map((item) {
              //         String input = item.data!.single.sIXCOUNT.toString(); //
              //         // 匹配到数字后，取出数字
              //         dynamic percentage;
              //         try {
              //           percentage = input.substring(input.indexOf("(") + 1, input.indexOf(")"));
              //         } catch (e) {
              //           percentage = "0.00";
              //         }
              //         //COUNT
              //          String count = item.data!.single.cOUNT.toString();
              //          String gROUPDATE = item.data!.single.gROUPDATE.toString();
              //         // 取出月份
              //         String month = gROUPDATE.substring(5, 7);
              //
              //         return Row(
              //           children: [
              //             Text("${gROUPDATE}       "),
              //             SizedBox(width: 10),
              //             Text("${item.reqCode?["empCode"]}-----"),
              //             InkWell(
              //               onTap: () {
              //                 "${month}月份(${count})票".copyValue();
              //               },
              //               child: Text(
              //                 "${month}月份(${count})票",
              //                 style: TextStyle(color: Colors.blue),
              //               ),
              //             ),
              //             SizedBox(width: 20),
              //             InkWell(
              //               onTap: () {
              //                 dynamic percentage;
              //                 try {
              //                   percentage = input.substring(input.indexOf("(") + 1, input.indexOf(")"));
              //                 } catch (e) {
              //                   percentage = "0.00";
              //                 }
              //                 try {
              //                   percentage = percentage.replaceAll("%", "");
              //                   percentage = double.parse(percentage).toStringAsFixed(1);
              //                   // 再 / 100
              //                   percentage = (double.parse(percentage) / 100);
              //                   percentage.toString().copyValue();
              //                 } catch (e) {
              //                   // 99.77%
              //                   percentage = "0.0";
              //                   percentage.toString().copyValue();
              //                 }
              //               },
              //               child: Text(
              //                 "${percentage}",
              //                 style: TextStyle(color: Colors.blue),
              //               ),
              //             )
              //           ],
              //         );
              //       }),
              //     ],
              //   ),
            ],
          )
        ],
      ),
    );
  }

  _buildRINCOSWidget() {
    return Container(
      width: double.infinity,
      padding: EdgeInsets.all(8),
      margin: EdgeInsets.symmetric(vertical: 10, horizontal: 2),
      decoration: BoxDecoration(border: Border.all(color: Colors.purpleAccent, width: 3), borderRadius: BorderRadius.circular(10)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                width: 300,
                child: TextField(
                  maxLines: null,
                  decoration: InputDecoration(labelText: "编号，多个用英文逗号隔开", border: OutlineInputBorder()),
                  onChanged: (value) {
                    accountNoStr = value.toString().trim();
                    if (accountNoStr.isNotEmpty) {
                      accountNo.clear();
                      accountNo.addAll(accountNoStr.split(","));
                    } else {
                      accountNo = [
                        "98181001",
                        "98181001A",
                      ];
                    }
                  },
                ),
              ),
              SizedBox(width: 10),
              rINCOSLoading
                  ? CircularProgressIndicator()
                  : ElevatedButton(
                      onPressed: () {
                        _weekReportBloc?.add(RINCOSEvent(accountNo: accountNo));
                      },
                      child: Text("rINCOS 获取数据"),
                    ),
            ],
          ),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text("RINCOS 未支付費用数据", style: TextStyle(color: Colors.purpleAccent)),
              if (rINCOSData.isNotEmpty)
                Column(
                  children: [
                    ElevatedButton(
                        onPressed: () {
                          StringBuffer sb = StringBuffer();
                          for (var value in rINCOSData.entries) {
                            sb.write("${value.key}\n");
                            for (var item in value.value) {
                              sb.write("${item.iDATE.toString()}\t"
                                  "${item.iCODE.toString()}\t"
                                  "${item.iMONEY.toString()}\t"
                                  "${item.cMNAME.toString()}\n");
                            }
                            sb.write("\t\t${value.value.fold(0, (value, element) => value + (element.iMONEY ?? 0))}\t");
                            sb.write("\n");
                            sb.write("\n");
                          }
                          sb.toString().copyValue();
                        },
                        child: Text("Copy All")),

                    // 正确结果
                    ...rINCOSData.entries.map((element) {
                      return Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Row(
                            children: [
                              Text("${element.key}"),
                              ElevatedButton(
                                  onPressed: () {
                                    StringBuffer sb = StringBuffer();
                                    for (var item in element.value) {
                                      sb.write("${item.iDATE.toString()}\t"
                                          "${item.iCODE.toString()}\t"
                                          "${item.iMONEY.toString()}\t"
                                          "${item.cMNAME.toString()}\n");
                                    }
                                    sb.write("\t\t${element.value.fold(0, (value, element) => value + (element.iMONEY ?? 0))}\t");
                                    sb.toString().copyValue();
                                  },
                                  child: Text("W")),
                            ],
                          ), // 编号
                          Table(children: [
                            // 数据
                            ...element.value.map((item) {
                              return TableRow(children: [
                                Text(item.iDATE.toString()),
                                Text(item.iCODE.toString()),
                                Text(item.iMONEY.toString()),
                                Text(item.cMNAME.toString())
                              ]);
                            }),

                            TableRow(children: [
                              TableCell(child: Text("")),
                              TableCell(child: Text("")),
                              TableCell(child: Text("（合计）${element.value.fold(0, (value, element) => value + (element.iMONEY ?? 0))}")),
                              TableCell(child: Text("")),
                            ]),
                          ]),
                        ],
                      );
                    }),

                    // ...rINCOSData.map((item) {
                    //   return Row(
                    //     children: [
                    //       GestureDetector(
                    //         onTap: () {},
                    //         child: Text(
                    //           "",
                    //           style: TextStyle(color: Colors.blue),
                    //         ),
                    //       )
                    //     ],
                    //   );
                    // }),
                  ],
                ),
            ],
          )
        ],
      ),
    );
  }

  _buildMonthFeeAndTaoPiaoWidget() {
    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        border: Border.all(color: Colors.teal, width: 3),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Text(" 月费及套票客户数据解析"),
              SizedBox(width: 10),
              ElevatedButton(
                  onPressed: () async {
                    _weekReportBloc?.add(MonthFeeAndTaoPiaoEvent(startDate: '$monthFeeStartDate', endDate: '$monthFeeEndDate'));
                  },
                  child: Text("获取数据")),
            ],
          ),
          Row(
            children: [
              CalendarView(
                day: 1,
                onInitDateChanged: (startDateTime, startStr, endDateTime, endStr) {
                  monthFeeStartDate = "${startStr.substring(0,10)}";
                  monthFeeEndDate = "${endStr.substring(0,10)}";
                },
                onDateStartChanged: (startDateTime, startStr) {
                  print("disMonthFeeStartDate: $startDateTime, $startStr");
                  monthFeeStartDate = "${startStr.substring(0,10)}";
                },
                onDateEndChanged: (endDateTime, endStr) {
                  print("disMonthFeeEndDate: $endDateTime, $endStr");
                  monthFeeEndDate = "${endStr.substring(0,10)}";
                },
              ),
            ],
          ),
          SizedBox(width: 10),
          Column(
            children: [
              Row(
                children: [
                  Text("原始數據"),
                  SizedBox(width: 30),
                  Text(
                    "规则：C 套票客、  N 月费客、  公司编号127忽略、  字符中包含客户介绍，替换成客户介绍文本、  轉套票，忽略数据",
                    style: TextStyle(color: Colors.red),
                  ),
                ],
              ),
              TextButton(
                  onPressed: () {
                    // 复制原始数据
                    StringBuffer sb = StringBuffer();
                    for (var item in originDataTemp) {
                      sb.write("${item.cMCODE.toString()}\t"
                          "${item.cMNAME.toString()}\t"
                          "${item.cMREGISTERBEGIN.toString()}\t"
                          "${item.cMREGISTEREND.toString()}\t"
                          "${item.cMMONTHCOST.toString()}\t"
                          "${item.cMORDERNUM.toString()}\t"
                          "${item.cMOVERFULL.toString()}\t"
                          "${item.bLCOST.toString()}\t"
                          "${item.bLBILLNUM.toString()}\t"
                          "${item.cMPHONE1.toString()}\t"
                          "${item.cMFAX1.toString()}\t"
                          "${item.cMTYPE.toString()}\t"
                          "${item.cMADDRESS.toString()}\t"
                          "${item.cMCONTACTS.toString()}\t"
                          "${item.bCCODE.toString()}\t"
                          "${item.bCNAME.toString()}\t"
                          "${item.bGCODE.toString()}\t"
                          "${item.bGCODE.toString()}\t"
                          "${item.cMREMARK.toString()}\t\n");
                    }
                    sb.toString().copyValue();
                  },
                  child: Text("W")),
              Row(
                children: [
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("客戶編號	", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("客戶名稱", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("開始日期	", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("停用日期", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("月費	", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("柯打數	", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("超件	", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("套票售出價", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("數量	", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("聯絡電話", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("傳真	", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("客戶類型	", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("地址	", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("客戶聯絡人	", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("公司編號	", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("公司名稱	", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("群組編號	", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("群組名稱", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("備註", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("操作", maxLines: 1))),
                ],
              ),
              ...originDataTemp.map((item) {
                return Row(
                  children: [
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text(item.cMCODE.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text(item.cMNAME.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(item.cMREGISTERBEGIN.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(item.cMREGISTEREND.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(item.cMMONTHCOST.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(item.cMORDERNUM.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(item.cMOVERFULL.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text(item.bLCOST.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(item.bLBILLNUM.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text(item.cMPHONE1.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text(item.cMFAX1.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text(item.cMTYPE.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(item.cMADDRESS.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(item.cMCONTACTS.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text(item.bCCODE.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text(item.bCNAME.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text(item.bGCODE.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text(item.bGCODE.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text(item.cMREMARK.toString(), maxLines: 1))),
                    Expanded(
                        child: InkWell(
                            onTap: () {
                              originDataTemp.remove(item);
                              setState(() {});
                            },
                            child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("删除", maxLines: 1)))),
                  ],
                );
              }),
              SizedBox(
                height: 10,
              ),
              Row(
                children: [
                  Text("月費客新增數據"),
                  ElevatedButton(
                      onPressed: () {
                        StringBuffer stringBuffer = new StringBuffer();
                        // stringBuffer.write("编号\t開戶日期\t群組\t客戶號碼\t客戶名稱\t地區\t月費\t柯打數量\t平均價\t備註\n");
                        for (int index = 0; index < nDataTemp.length; index++) {
                          stringBuffer.write("${index + 1}\t"
                              "${nDataTemp[index].cMREGISTERBEGIN.toString()}\t"
                              "${nDataTemp[index].t.toString()}\t"
                              "${nDataTemp[index].cMCODE.toString()}\t"
                              "${nDataTemp[index].cMNAME.toString()}\t"
                              "${nDataTemp[index].cMADDRESS.toString()}\t"
                              "${nDataTemp[index].cMMONTHCOST.toString()}\t"
                              "${nDataTemp[index].cMORDERNUM.toString()}\t"
                              "${nDataTemp[index].u}\t"
                              "${nDataTemp[index].cMREMARK.toString()}\t\n");
                        }

                        stringBuffer.toString().copyValue();
                      },
                      child: Text("W")),
                ],
              ),
              Row(
                children: [
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.red, width: 1)), child: Text("编号", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.red, width: 1)), child: Text("開戶日期", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.red, width: 1)), child: Text("群組", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.red, width: 1)), child: Text("客户號碼", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.red, width: 1)), child: Text("客户名稱", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.red, width: 1)), child: Text("地區", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.red, width: 1)), child: Text("月費", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.red, width: 1)), child: Text("柯打數量", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.red, width: 1)), child: Text("平均價", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.red, width: 1)), child: Text("備註", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.red, width: 1)), child: Text("操作", maxLines: 1))),
                ],
              ),
              ...nDataTemp.asMap().keys.map((index) {
                return Row(
                  children: [
                    Expanded(
                        child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.red, width: 1)), child: Text("${index + 1}", maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(nDataTemp[index].cMREGISTERBEGIN.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.red, width: 1)),
                            child: Text(nDataTemp[index].t.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(nDataTemp[index].cMCODE.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(nDataTemp[index].cMNAME.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.red, width: 1)),
                            child: Text(nDataTemp[index].cMADDRESS.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(nDataTemp[index].cMMONTHCOST.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(nDataTemp[index].cMORDERNUM.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.red, width: 1)), child: Text("${nDataTemp[index].u}", maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.red, width: 1)),
                            child: Text(nDataTemp[index].cMREMARK.toString(), maxLines: 1))),
                    Expanded(
                        child: InkWell(
                            onTap: () {
                              nDataTemp.removeAt(index);
                              setState(() {});
                            },
                            child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("删除", maxLines: 1)))),
                  ],
                );
              }),
              SizedBox(height: 10),
              Row(
                children: [
                  Text("套票客新增數據"),
                  ElevatedButton(
                      onPressed: () {
                        StringBuffer stringBuffer = new StringBuffer();
                        for (int index = 0; index < cDataTemp.length; index++) {
                          stringBuffer.write("${index + 1}\t"
                              "${cDataTemp[index].cMREGISTERBEGIN.toString()}\t"
                              "${cDataTemp[index].t.toString()}\t"
                              "${cDataTemp[index].cMCODE.toString()}\t"
                              "${cDataTemp[index].cMNAME.toString()}\t"
                              "${cDataTemp[index].cMADDRESS.toString().replaceAll("\r", " ").replaceAll("\n", " ")}\t"
                              "${cDataTemp[index].bLCOST ?? ""}\t"
                              "${cDataTemp[index].bLBILLNUM ?? ""}\t"
                              "${cDataTemp[index].u ?? ""}\t"
                              "一年\t"
                              "${cDataTemp[index].cMREMARK.toString().replaceAll("\n", " ")}\t\n");
                        }

                        double bLCOSTAll = cDataTemp.fold(0.00, (value, element) => value + (element.bLCOST ?? 0));
                        double bLBILLNUMAll = cDataTemp.fold(0.00, (value, element) => value + (element.bLBILLNUM ?? 0));
                        double u_temp = bLCOSTAll / bLBILLNUMAll;

                        stringBuffer.write("\t\t\t\t\t\t");
                        stringBuffer.write("${bLCOSTAll}\t${bLBILLNUMAll}\t${u_temp}\t\t");

                        stringBuffer.toString().copyValue();
                      },
                      child: Text("W")),
                ],
              ),
              Row(
                children: [
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 1)), child: Text("编号", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 1)), child: Text("開戶日期", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 1)), child: Text("群組", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 1)), child: Text("客户號碼", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 1)), child: Text("客户名稱", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 1)), child: Text("地區", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 1)), child: Text("銷售銀碼", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 1)), child: Text("套票數量", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 1)), child: Text("平均價", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 1)), child: Text("有效期", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 1)), child: Text("備註", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 1)), child: Text("操作", maxLines: 1))),
                ],
              ),
              ...cDataTemp.asMap().keys.map((index) {
                return Row(
                  children: [
                    Expanded(
                        child:
                            Container(decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 1)), child: Text("${index + 1}", maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(cDataTemp[index].cMREGISTERBEGIN.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 1)),
                            child: Text(cDataTemp[index].t.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(cDataTemp[index].cMCODE.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(cDataTemp[index].cMNAME.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 1)),
                            child: Text(cDataTemp[index].cMADDRESS.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(cDataTemp[index].bLCOST.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(cDataTemp[index].bLBILLNUM.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 1)), child: Text("${cDataTemp[index].u}", maxLines: 1))),
                    Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 1)), child: Text("一年", maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.black, width: 1)),
                            child: Text(cDataTemp[index].cMREMARK.toString(), maxLines: 1))),
                    Expanded(
                        child: InkWell(
                            onTap: () {
                              cDataTemp.removeAt(index);
                              setState(() {});
                            },
                            child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("删除", maxLines: 1)))),
                  ],
                );
              }),
              SizedBox(
                height: 10,
              ),
              Row(
                children: [
                  Text("寶箱數據"),
                  ElevatedButton(
                      onPressed: () {
                        StringBuffer stringBuffer = new StringBuffer();
                        // stringBuffer.write("開戶日期\t客戶號碼\t群組\t客戶號碼\t客戶名稱\t地區\t月費\t柯打數量\t平均價\t地址\n");
                        for (int i = 0; i < bDataTemp.length; i++) {
                          stringBuffer.write("${bDataTemp[i].cMREGISTERBEGIN}\t"
                              "${bDataTemp[i].cMCODE.toString()}\t"
                              "\t"
                              "\t"
                              "1\t"
                              "${bDataTemp[i].cMNAME.toString()}\t"
                              "${bDataTemp[i].cMADDRESS.toString()}\n");
                        }
                        stringBuffer.toString().copyValue();
                      },
                      child: Text("W")),
                ],
              ),
              Row(
                children: [
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.green, width: 1)), child: Text("開戶日期", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.green, width: 1)), child: Text("客戶號碼", maxLines: 1))),
                  Expanded(
                      child:
                          Container(decoration: BoxDecoration(border: Border.all(color: Colors.green, width: 1)), child: Text("\$999/\$99/50", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.green, width: 1)), child: Text("絕袋箱驕", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.green, width: 1)), child: Text("宝箱", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.green, width: 1)), child: Text("客戶名稱", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.green, width: 1)), child: Text("地址", maxLines: 1))),
                  Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.green, width: 1)), child: Text("操作", maxLines: 1))),
                ],
              ),
              ...bDataTemp.asMap().keys.map((index) {
                return Row(
                  children: [
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(bDataTemp[index].cMREGISTERBEGIN.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(bDataTemp[index].cMNAME.toString(), maxLines: 1))),
                    Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.green, width: 1)), child: Text("", maxLines: 1))),
                    Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.green, width: 1)), child: Text("", maxLines: 1))),
                    Expanded(child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.green, width: 1)), child: Text("", maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)),
                            child: Text(bDataTemp[index].cMNAME.toString(), maxLines: 1))),
                    Expanded(
                        child: Container(
                            decoration: BoxDecoration(border: Border.all(color: Colors.green, width: 1)),
                            child: Text(bDataTemp[index].cMADDRESS.toString(), maxLines: 1))),
                    Expanded(
                        child: InkWell(
                            onTap: () {
                              bDataTemp.removeAt(index);
                              setState(() {});
                            },
                            child: Container(decoration: BoxDecoration(border: Border.all(color: Colors.indigo, width: 1)), child: Text("删除", maxLines: 1)))),
                  ],
                );
              }),
            ],
          ),
          Text("月费停用数据"),
        ],
      ),
    );
  }

  // 套票销售及使用
  _buildTaoPiaoXiaoShouShiYongWidget() {
    return Container(
      margin: EdgeInsets.symmetric(vertical: 10),
      decoration: BoxDecoration(
        border: Border.all(color: Colors.red, width: 3),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              taoPiaoXiaoShouShiYongLoading
                  ? CircularProgressIndicator()
                  : TextButton(
                      onPressed: () {
                        if (taoPiaoXiaoShouShiYongLoading) return;
                        _weekReportBloc?.add(TaoPiaoXiaoShouShiYongEvent(startDate: waybillPrintingStart, endDate: waybillPrintingEnd));
                      },
                      child: Text("套票销售及使用  获取数据"),
                    ),
              CalendarView(
                day: 1,
                onInitDateChanged: (startDateTime, startStr, endDateTime, endStr) {
                  waybillPrintingStart = "${startStr}";
                  waybillPrintingEnd = "${endStr}";
                },
                onDateStartChanged: (startDateTime, startStr) {
                  print("disMonthFeeStartDate: $startDateTime, $startStr");
                  waybillPrintingStart = "${startStr}";
                },
                onDateEndChanged: (endDateTime, endStr) {
                  print("disMonthFeeEndDate: $endDateTime, $endStr");
                  waybillPrintingEnd = "${endStr}";
                },
              ),
            ],
          ),
          Column(
            children: [
              //  dynamic resultData;
              //   DailyInformationBean? dailyInformationBean;
              //   DailyVoteBean? dailyVoteBean;
              if (resultData != null) ...[
                Table(
                  children: [
                    tabRows([
                      "月份",
                      "直客	銷售票數",
                      "直客	使用票數",
                      "加盟商	銷售票數",
                      "加盟商	使用票數",
                    ]),
                    TableRow(children: [
                      TableCell(
                          child: Text(
                        resultData["current_date"],
                        style: TextStyle(fontSize: 14),
                        textAlign: TextAlign.center,
                      )),
                      TableCell(
                          child: Text(
                        resultData["zhuKesCount"].toString(),
                        style: TextStyle(fontSize: 14),
                        textAlign: TextAlign.center,
                      )),
                      TableCell(
                          child: Text(
                        resultData["tpZK"].toString(),
                        style: TextStyle(fontSize: 14),
                        textAlign: TextAlign.center,
                      )),
                      TableCell(
                          child: Text(
                        resultData["jiaMansCount"].toString(),
                        style: TextStyle(fontSize: 14),
                        textAlign: TextAlign.center,
                      )),
                      TableCell(
                          child: Text(
                        resultData["tPJM"].toString(),
                        style: TextStyle(fontSize: 14),
                        textAlign: TextAlign.center,
                      )),
                    ]),
                  ],
                ),
              ],
              ElevatedButton(
                  onPressed: () {
                    "${resultData["current_date"].toString()}\t"
                            "${resultData["zhuKesCount"].toString()}\t"
                            "${resultData["tpZK"].toString()}\t"
                            "${resultData["jiaMansCount"].toString()}\t"
                            "${resultData["tPJM"].toString()}\t"
                        .copyValue();
                  },
                  child: Text("copy data")),
            ],
          )
        ],
      ),
    );
  }

  // 外判佔比
  _buildWaiPanZhanBiWidget() {
    return Container(
      decoration: BoxDecoration(
        border: Border.all(color: Colors.blue, width: 3),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              waiPanZhanBiLoading
                  ? CircularProgressIndicator()
                  : TextButton(
                      onPressed: () {
                        if (waiPanZhanBiLoading) return;
                        _weekReportBloc?.add(WaiPanZhanBiEvent(startDate: waiPanZhanBiStartDate, endDate: waiPanZhanBiEndDate));
                      },
                      child: Text("外判佔比  获取数据"),
                    ),
              CalendarView(
                day: 1,
                onInitDateChanged: (startDateTime, startStr, endDateTime, endStr) {
                  waiPanZhanBiStartDate = "${startStr}";
                  waiPanZhanBiEndDate = "${endStr}";
                },
                onDateStartChanged: (startDateTime, startStr) {
                  print("disMonthFeeStartDate: $startDateTime, $startStr");
                  waiPanZhanBiStartDate = "${startStr}";
                },
                onDateEndChanged: (endDateTime, endStr) {
                  print("disMonthFeeEndDate: $endDateTime, $endStr");
                  waiPanZhanBiEndDate = "${endStr}";
                },
              ),
            ],
          ),
          Column(
            children: [
              if (independentStatisticalBean != null)
                Table(
                  children: [
                    tabRows(["日期", "Rincos", "Ocs收", "Ocs派", "九恆", "Konica", "Godwell", "CXC集運", "LX", "SASA", "其它", "合計"]),
                    ...independentStatisticalBean!.data!.map((e) => TableRow(children: [
                          TableCell(
                              child: Text(
                            e.dateTime.toString(),
                            textAlign: TextAlign.center,
                          )),
                          TableCell(
                              child: Text(
                            e.rINCOS.toString(),
                            textAlign: TextAlign.center,
                          )),
                          TableCell(
                              child: Text(
                            e.OCSShou.toString(),
                            textAlign: TextAlign.center,
                          )),
                          TableCell(
                              child: Text(
                            e.OCSPai.toString(),
                            textAlign: TextAlign.center,
                          )),
                          TableCell(
                              child: Text(
                            e.jiuheng.toString(),
                            textAlign: TextAlign.center,
                          )),
                          TableCell(
                              child: Text(
                            e.Konica.toString(),
                            textAlign: TextAlign.center,
                          )),
                          // TableCell(child: Text(e.lINEX.toString(),textAlign: TextAlign.center,)),
                          TableCell(
                              child: Text(
                            e.gODWELL.toString(),
                            textAlign: TextAlign.center,
                          )),
                          TableCell(
                              child: Text(
                            e.consolidationTransportation.toString(),
                            textAlign: TextAlign.center,
                          )),
                          TableCell(
                              child: Text(
                            e.lX.toString(),
                            textAlign: TextAlign.center,
                          )),
                          TableCell(
                              child: Text(
                            e.sASA.toString(),
                            textAlign: TextAlign.center,
                          )),
                          TableCell(
                              child: Text(
                            e.otherIt.toString(),
                            textAlign: TextAlign.center,
                          )),
                          TableCell(
                              child: Text(
                            e.total.toString(),
                            style: TextStyle(color: Colors.blue),
                            textAlign: TextAlign.center,
                          )),
                        ])),
                    tabRowWidgets([
                      Text("合计", style: TextStyle(color: Colors.red)),
                      Text("${independentStatisticalBean!.data?.fold(0, (value, element) => value + (element.rINCOS ?? 0))}",
                          style: TextStyle(color: Colors.red), textAlign: TextAlign.center),
                      Text("${independentStatisticalBean!.data?.fold(0, (value, element) => value + (element.OCSShou ?? 0))}",
                          style: TextStyle(color: Colors.red), textAlign: TextAlign.center),
                      Text("${independentStatisticalBean!.data?.fold(0, (value, element) => value + (element.OCSPai ?? 0))}",
                          style: TextStyle(color: Colors.red), textAlign: TextAlign.center),
                      Text("${independentStatisticalBean!.data?.fold(0, (value, element) => value + (element.jiuheng ?? 0))}",
                          style: TextStyle(color: Colors.red), textAlign: TextAlign.center),
                      Text("${independentStatisticalBean!.data?.fold(0, (value, element) => value + (element.Konica ?? 0))}",
                          style: TextStyle(color: Colors.red), textAlign: TextAlign.center),
                      // Text("${independentStatisticalBean!.data?.fold(0, (value, element) => value + (element.lINEX ?? 0))}", style: TextStyle(color: Colors.red),textAlign: TextAlign.center),
                      Text("${independentStatisticalBean!.data?.fold(0, (value, element) => value + (element.gODWELL ?? 0))}",
                          style: TextStyle(color: Colors.red), textAlign: TextAlign.center),
                      Text("${independentStatisticalBean!.data?.fold(0, (value, element) => value + (element.consolidationTransportation ?? 0))}",
                          style: TextStyle(color: Colors.red), textAlign: TextAlign.center),
                      Text("${independentStatisticalBean!.data?.fold(0, (value, element) => value + (element.lX ?? 0))}",
                          style: TextStyle(color: Colors.red), textAlign: TextAlign.center),
                      Text("${independentStatisticalBean!.data?.fold(0, (value, element) => value + (element.sASA ?? 0))}",
                          style: TextStyle(color: Colors.red), textAlign: TextAlign.center),
                      Text("${independentStatisticalBean!.data?.fold(0, (value, element) => value + (element.otherIt ?? 0))}",
                          style: TextStyle(color: Colors.red), textAlign: TextAlign.center),
                      Text("${independentStatisticalBean!.data?.fold(0, (value, element) => value + (element.total ?? 0))}",
                          style: TextStyle(color: Colors.red), textAlign: TextAlign.center)
                    ]),
                  ],
                ),
              if (localDeliveryStatisticsBean != null)
                Table(
                  children: [
                    tabRows([
                      "入场时间",
                      "本地件入場(同城)",
                      "簽收(同城)",
                      "簽收率(同城)",
                      "電商件入場",
                      "簽收(電商)\n(電商件入場*簽收率(電商件))",
                      "簽收率(電商件)",
                      "總件數(入場)\n(本地件入場(同城)+電商件入場)",
                      "簽收(整體)\n(總件數(入場)*總簽收率)",
                      "總簽收率"
                    ]),
                    ...localDeliveryStatisticsBean!.data!.map((e) => TableRow(children: [
                          TableCell(child: Text(e.sCANDATE.toString(), textAlign: TextAlign.center)),
                          TableCell(child: Text(e.lOCALBUSSINS.toString(), style: TextStyle(color: Colors.green), textAlign: TextAlign.center)),
                          TableCell(child: Text(e.sIGNSAMECITY.toString(), textAlign: TextAlign.center)),
                          TableCell(child: Text(e.sIGNRATESAMECITY.toString(), textAlign: TextAlign.center)),
                          TableCell(child: Text(e.oNLINEBUSSINS.toString(), style: TextStyle(color: Colors.blue), textAlign: TextAlign.center)),
                          TableCell(child: Text(e.sIGNONLINE.toString(), textAlign: TextAlign.center)),
                          TableCell(child: Text(e.sIGNRATEONLINE.toString(), textAlign: TextAlign.center)),
                          TableCell(child: Text(e.cOUNTBUSSINS.toString(), textAlign: TextAlign.center)),
                          TableCell(child: Text(e.sIGNCOUNT.toString(), textAlign: TextAlign.center)),
                          TableCell(child: Text(e.sIGNCOUNTONLINE.toString(), textAlign: TextAlign.center)),
                        ])),
                    tabRowWidgets([
                      Text("合计", style: TextStyle(color: Colors.red)),
                      Text("${localDeliveryStatisticsBean!.data?.fold(0, (value, element) => value + (element.lOCALBUSSINS ?? 0))}",
                          style: TextStyle(color: Colors.red)),
                      Text("${localDeliveryStatisticsBean!.data?.fold(0, (value, element) => value + (element.sIGNSAMECITY ?? 0))}",
                          style: TextStyle(color: Colors.red)),
                      Text(
                          "${(localDeliveryStatisticsBean!.data!.fold(0, (value, element) => value + (element.sIGNSAMECITY ?? 0)).toDouble() / (localDeliveryStatisticsBean!.data!.fold(0, (value, element) => value + (element.lOCALBUSSINS ?? 0)).toDouble()) * 100).toStringAsFixed(2)}%",
                          style: TextStyle(color: Colors.red)),
                      Text("${localDeliveryStatisticsBean!.data?.fold(0, (value, element) => value + (element.oNLINEBUSSINS ?? 0))}",
                          style: TextStyle(color: Colors.red)),
                      Text("${localDeliveryStatisticsBean!.data?.fold(0, (value, element) => value + (element.sIGNONLINE ?? 0))}",
                          style: TextStyle(color: Colors.red)),
                      Text(
                          "${(localDeliveryStatisticsBean!.data!.fold(0, (value, element) => value + (element.sIGNONLINE ?? 0)).toDouble() / (localDeliveryStatisticsBean!.data!.fold(0, (value, element) => value + (element.oNLINEBUSSINS ?? 0)).toDouble()) * 100).toStringAsFixed(2)}%",
                          style: TextStyle(color: Colors.red)),
                      Text("${localDeliveryStatisticsBean!.data?.fold(0, (value, element) => value + (element.cOUNTBUSSINS ?? 0))}",
                          style: TextStyle(color: Colors.red)),
                      Text("${localDeliveryStatisticsBean!.data?.fold(0, (value, element) => value + (element.sIGNCOUNT ?? 0))}",
                          style: TextStyle(color: Colors.red)),
                      Text(
                          "${(localDeliveryStatisticsBean!.data!.fold(0, (value, element) => value + (element.sIGNCOUNT ?? 0)).toDouble() / (localDeliveryStatisticsBean!.data!.fold(0, (value, element) => value + (element.cOUNTBUSSINS ?? 0)).toDouble()) * 100).toStringAsFixed(2)}%",
                          style: TextStyle(color: Colors.red)),
                    ]),
                  ],
                ),
              if (thirdPartyBean != null)
                Table(
                  children: [
                    tabRows(["日期", "菜烏", " 電單車 ", "貨VAN", "電單車", "貨VAN", "同城件", "電商件"]),
                    ...thirdPartyBean!.data!.map((e) => TableRow(children: [
                          TableCell(child: Text(e.cREATEDATE.toString())),
                          TableCell(child: Text(e.aF.toString())),
                          TableCell(child: Text(e.tCDDC.toString())),
                          TableCell(child: Text(e.tCHVAN.toString())),
                          TableCell(child: Text(e.dSDDC.toString())),
                          TableCell(child: Text(e.dSHVAN.toString())),
                          TableCell(child: Text(e.tCJ.toString())),
                          TableCell(child: Text(e.dSJ.toString())),
                        ])),
                    tabRowWidgets([
                      Text("日期 （总数）"),
                      copyWidget(Text("${thirdPartyBean!.data!.fold(0, (value, element) => value + (element.aF ?? 0))}")),
                      copyWidget(Text("${thirdPartyBean!.data!.fold(0, (value, element) => value + (element.tCDDC ?? 0))}")),
                      copyWidget(Text("${thirdPartyBean!.data!.fold(0, (value, element) => value + (element.tCHVAN ?? 0))}")),
                      copyWidget(Text("${thirdPartyBean!.data!.fold(0, (value, element) => value + (element.dSDDC ?? 0))}")),
                      copyWidget(Text("${thirdPartyBean!.data!.fold(0, (value, element) => value + (element.dSHVAN ?? 0))}")),
                      copyWidget(Text("${thirdPartyBean!.data!.fold(0, (value, element) => value + (element.tCJ ?? 0))}")),
                      copyWidget(Text("${thirdPartyBean!.data!.fold(0, (value, element) => value + (element.dSJ ?? 0))}")),
                    ]),
                  ],
                ),
              Divider(height: 10, color: Colors.red),
              if (cmsTicketBean != null)
                Table(
                  children: [
                    tabRows(["日期", "同城件票數", "內含CMS", "內含城市", "內含ACS", "電商件票數", "全公司整體票數\n(同城件票數+電商件票數)"]),
                    ...cmsTicketBean!.data!.map((e) => TableRow(children: [
                          TableCell(child: Text(e.gROUPDATE.toString())),
                          TableCell(child: Text(e.tCCOUNT.toString(), style: const TextStyle(color: Colors.green))),
                          TableCell(child: Text(e.cMSCOUNT.toString())),
                          TableCell(child: Text(e.cITYCOUNT.toString())),
                          TableCell(child: Text(e.aCSCOUNT.toString())),
                          TableCell(child: Text(e.dSCOUNT.toString(), style: const TextStyle(color: Colors.blue))),
                          TableCell(child: Text(e.aLLCOUNT.toString())),
                        ])),
                    tabRowWidgets([
                      Text("日期 （总数）"),
                      copyWidget(Text("${cmsTicketBean!.data!.fold(0, (value, element) => value + (element.tCCOUNT ?? 0))}")),
                      copyWidget(Text("${cmsTicketBean!.data!.fold(0, (value, element) => value + (element.cMSCOUNT ?? 0))}")),
                      copyWidget(Text("${cmsTicketBean!.data!.fold(0, (value, element) => value + (element.cITYCOUNT ?? 0))}")),
                      copyWidget(Text("${cmsTicketBean!.data!.fold(0, (value, element) => value + (element.aCSCOUNT ?? 0))}")),
                      copyWidget(Text("${cmsTicketBean!.data!.fold(0, (value, element) => value + (element.dSCOUNT ?? 0))}")),
                      copyWidget(Text("${cmsTicketBean!.data!.fold(0, (value, element) => value + (element.aLLCOUNT ?? 0))}"))
                    ]),
                  ],
                ),
              Divider(height: 10, color: Colors.red),
              Text("外判佔比数据", style: TextStyle(fontSize: 18)),
              if (waiPanZhanBiData != null)
                Table(
                  children: [
                    tabRows(["菜烏", " 電單車 ", "貨VAN", "電單車", "貨VAN", "同城件", "電商件", "合計", "該月總票數", "佔比"]),
                    TableRow(children: [
                      TableCell(child: Text(waiPanZhanBiData!.aF.toString())),
                      TableCell(child: Text(waiPanZhanBiData!.tCDDC.toString())),
                      TableCell(child: Text(waiPanZhanBiData!.tCHVAN.toString())),
                      TableCell(child: Text(waiPanZhanBiData!.dSDDC.toString())),
                      TableCell(child: Text(waiPanZhanBiData!.dSHVAN.toString())),
                      TableCell(child: Text(waiPanZhanBiData!.tCJ.toString())),
                      TableCell(child: Text(waiPanZhanBiData!.dSJ.toString())),
                      TableCell(child: Text(waiPanZhanBiData!.total.toString())),
                      TableCell(child: Text(waiPanZhanBiData!.cmsTotal.toString())),
                      TableCell(child: Text(waiPanZhanBiData!.percent.toString())),
                    ]),
                  ],
                ),
              ElevatedButton(
                  onPressed: () {
                    "${waiPanZhanBiData!.aF.toString()}\t"
                            "${waiPanZhanBiData!.tCDDC.toString()}\t"
                            "${waiPanZhanBiData!.tCHVAN.toString()}\t"
                            "${waiPanZhanBiData!.dSDDC.toString()}\t"
                            "${waiPanZhanBiData!.dSHVAN.toString()}\t"
                            "${waiPanZhanBiData!.tCJ.toString()}\t"
                            "${waiPanZhanBiData!.dSJ.toString()}\t"
                            "${waiPanZhanBiData!.total.toString()}\t"
                            "${waiPanZhanBiData!.cmsTotal.toString()}\t"
                            "${waiPanZhanBiData!.percent.toString()}\t"
                        .copyValue();
                  },
                  child: Text("copy data")),
            ],
          )
        ],
      ),
    );
  }

  // 新电商比较
  _buildNewDianShangWidget() {
    return Container(
      margin: const EdgeInsets.symmetric(vertical: 10),
      decoration: BoxDecoration(
        border: Border.all(color: Colors.green, width: 3),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            "电商表元数据",
            style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.green),
          ),
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              CalendarView(
                day: 1,
                onInitDateChanged: (startDateTime, startStr, endDateTime, endStr) {
                  newDianShangStartDate = "${startStr}";
                  newDianShangEndDate = "${endStr}";
                },
                onDateStartChanged: (startDateTime, startStr) {
                  print("disMonthFeeStartDate: $startDateTime, $startStr");
                  newDianShangStartDate = "${startStr}";
                },
                onDateEndChanged: (endDateTime, endStr) {
                  print("disMonthFeeEndDate: $endDateTime, $endStr");
                  newDianShangEndDate = "${endStr}";
                },
              ),
              MenuAnchor(
                childFocusNode: _newOldDianShangFocusNode,
                menuChildren: [
                  ...List.generate(12, (index) {
                    return MenuItemButton(
                      child: Text("选择月份${index + 1}"),
                      onPressed: () {
                        selectMonth = "选择月份${index + 1}";
                        setState(() {});
                      },
                    );
                  }),
                ],
                builder: (_, controller, child) {
                  return Container(
                    child: selectMonth == ""
                        ? TextButton(
                            focusNode: _newOldDianShangFocusNode,
                            onPressed: () {
                              if (controller.isOpen) {
                                controller.close();
                              } else {
                                controller.open();
                              }
                            },
                            child: Text(
                              "请选择月份",
                              style: TextStyle(color: Colors.black),
                            ))
                        : TextButton(
                            focusNode: _newOldDianShangFocusNode,
                            onPressed: () {
                              if (controller.isOpen) {
                                controller.close();
                              } else {
                                controller.open();
                              }
                            },
                            child: Text(
                              selectMonth,
                              style: TextStyle(color: Colors.black),
                            )),
                  );
                },
              ),
              (newDianShangLoading)
                  ? Center(child: CircularProgressIndicator())
                  : ElevatedButton(
                      onPressed: () {
                        int month = int.parse(selectMonth.replaceAll("选择月份", ""));
                        _weekReportBloc?.add(DianShangDataEvent(startDate: newDianShangStartDate, endDate: newDianShangEndDate, month: month));
                      },
                      child: Text(
                        "获取",
                        style: TextStyle(color: Colors.green, fontSize: 16),
                      ),
                    ),
            ],
          ),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              ElevatedButton(
                  onPressed: () {
                    StringBuffer sb = StringBuffer();
                    for (var element in existenceData) {
                      sb.write("${element.cMCODE}\t${element.cMNAME}\t");
                      for (var e in element.requiredCounts!.reversed) {
                        sb.write("${e}\t");
                      }
                      sb.write("\n");
                    }
                    sb.toString().copyValue();
                  },
                  child: Text("W")),
              if (existenceData.isNotEmpty)
                Table(
                  children: [
                    TableRow(children: [
                      TableCell(child: Text("编号", style: TextStyle(color: Colors.red))),
                      TableCell(child: Text("名称", style: TextStyle(color: Colors.red))),
                      ...monthCounts.reversed.map((element) {
                        return TableCell(child: Text("${element.toString()}月", style: TextStyle(color: Colors.red, fontSize: 16)));
                      }),
                    ]),
                    ...existenceData.map((element) {
                      return TableRow(children: [
                        TableCell(child: Text(element.cMCODE.toString(), style: TextStyle(color: Colors.red))),
                        TableCell(child: Text(element.cMNAME.toString(), maxLines: 1, overflow: TextOverflow.ellipsis)),
                        ...element.requiredCounts!.reversed.map((e) {
                          return TableCell(child: Text(e.toString()));
                        }),
                      ]);
                    })
                  ],
                ),
              if (nData.isNotEmpty)
                ElevatedButton(
                    onPressed: () {
                      StringBuffer sb = StringBuffer();
                      for (var element in nData) {
                        sb.write("${element.cMCODE}\t${element.cMNAME}\t");
                        for (var e in element.requiredCounts!.reversed) {
                          sb.write("${e}\t");
                        }
                        sb.write("\n");
                      }
                      sb.toString().copyValue();
                    },
                    child: Text("W")),
              Table(
                children: [
                  ...nData.map((element) {
                    return TableRow(children: [
                      TableCell(child: Text(element.cMCODE.toString())),
                      TableCell(child: Text(element.cMNAME.toString(), maxLines: 1, overflow: TextOverflow.ellipsis)),
                      ...element.requiredCounts!.reversed.map((e) {
                        return TableCell(child: Text(e.toString()));
                      }),
                    ]);
                  })
                ],
              ),
            ],
          ),
        ],
      ),
    );
  }

  _buildSummaryDataWidget() {
    return Container(
      decoration: BoxDecoration(border: Border.all(color: Colors.red, width: 3)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text("汇总数据", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.red)),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              (summaryDataLoading)
                  ? Center(child: CircularProgressIndicator())
                  : ElevatedButton(
                      onPressed: () {
                        _weekReportBloc
                            ?.add(HuiZongDataEvent(startDate: huizongStartDate, endDate: huizongEndDate, nDataTemp: nDataTemp, cDataTemp: cDataTemp));
                      },
                      child: Text("汇总解析")),
              CalendarView(
                day: 1,
                onInitDateChanged: (startDateTime, startStr, endDateTime, endStr) {
                  huizongStartDate = "${startStr}";
                  huizongEndDate = "${endStr}";
                },
                onDateStartChanged: (startDateTime, startStr) {
                  print("disMonthFeeStartDate: $startDateTime, $startStr");
                  huizongStartDate = "${startStr}";
                },
                onDateEndChanged: (endDateTime, endStr) {
                  print("disMonthFeeEndDate: $endDateTime, $endStr");
                  huizongEndDate = "${endStr}";
                },
              ),
            ],
          ),
          Column(
            children: [
              if (monthData.isNotEmpty)
                Container(
                  decoration: BoxDecoration(
                    border: Border.all(color: Colors.blue, width: 3),
                  ),
                  child: Column(
                    children: [
                      Row(
                        children: [
                          Text("新增月費客戶狀況", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.blue)),
                          ElevatedButton(
                            onPressed: () {
                              StringBuffer sb = StringBuffer();
                              sb.write("${monthData["monthZE"]}\t"
                                  "${monthData["monthZongCount"]}\t"
                                  "${monthData["jmsMonthZE"]}\t"
                                  "${monthData["jmsMonthCount"]}\t"
                                  "${monthData["jmsMonthPercent"]}\t"
                                  "${monthData["zhuKesMonthZE"]}\t"
                                  "${monthData["zhuKesMonthCount"]}\t"
                                  "${monthData["zhuKesMonthPercent"]}");
                              sb.toString().copyValue();
                            },
                            child: Text("W"),
                          ),
                        ],
                      ),
                      Table(
                        children: [
                          TableRow(children: [
                            TableCell(child: Text("月費\n總收入")),
                            TableCell(child: Text("客戶\n數目")),
                            TableCell(child: Text("月費\n總收入")),
                            TableCell(child: Text("客戶數目")),
                            TableCell(child: Text("百份比")),
                            TableCell(child: Text("月費\n總收入")),
                            TableCell(child: Text("客戶數目")),
                            TableCell(child: Text("百份比")),
                          ]),
                          TableRow(children: [
                            TableCell(child: Text("${monthData["monthZE"]}")),
                            TableCell(child: Text("${monthData["monthZongCount"]}")),
                            TableCell(child: Text("${monthData["jmsMonthZE"]}")),
                            TableCell(child: Text("${monthData["jmsMonthCount"]}")),
                            TableCell(child: Text("${monthData["jmsMonthPercent"]}")),
                            TableCell(child: Text("${monthData["zhuKesMonthZE"]}")),
                            TableCell(child: Text("${monthData["zhuKesMonthCount"]}")),
                            TableCell(child: Text("${monthData["zhuKesMonthPercent"]}"))
                          ]),
                        ],
                      )
                    ],
                  ),
                ),
              if (tpData.isNotEmpty)
                Container(
                  decoration: BoxDecoration(
                    border: Border.all(color: Colors.red, width: 3),
                  ),
                  child: Column(
                    children: [
                      Row(
                        children: [
                          Text("新增套票客戶狀況", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.blue)),
                          ElevatedButton(
                            onPressed: () {
                              StringBuffer sb = StringBuffer();

                              sb.write("${tpData["tpAllZE"]}\t"
                                  "${tpData["tpAllCount"]}\t"
                                  "${tpData["jmsZE"]}\t"
                                  "${tpData["jmsCount"]}\t"
                                  "${tpData["jmsPercent"]}\t"
                                  "${tpData["zhuKesZE"]}\t"
                                  "${tpData["zhuKesCount"]}\t"
                                  "${tpData["zhuKesPercent"]}");
                              sb.toString().copyValue();
                            },
                            child: Text("W"),
                          ),
                        ],
                      ),
                      Table(
                        children: [
                          TableRow(children: [
                            TableCell(child: Text("月費\n總收入")),
                            TableCell(child: Text("客戶\n數目")),
                            TableCell(child: Text("月費\n總收入")),
                            TableCell(child: Text("客戶數目")),
                            TableCell(child: Text("百份比")),
                            TableCell(child: Text("月費\n總收入")),
                            TableCell(child: Text("客戶數目")),
                            TableCell(child: Text("百份比")),
                          ]),
                          TableRow(children: [
                            TableCell(child: Text("${tpData["tpAllZE"]}")),
                            TableCell(child: Text("${tpData["tpAllCount"]}")),
                            TableCell(child: Text("${tpData["jmsZE"]}")),
                            TableCell(child: Text("${tpData["jmsCount"]}")),
                            TableCell(child: Text("${tpData["jmsPercent"]}")),
                            TableCell(child: Text("${tpData["zhuKesZE"]}")),
                            TableCell(child: Text("${tpData["zhuKesCount"]}")),
                            TableCell(child: Text("${tpData["zhuKesPercent"]}")),
                          ]),
                        ],
                      ),
                    ],
                  ),
                ),
              Container(
                child: Table(
                  children: [
                    tabRows(["月份", "套票\n總收入", "客戶\n數目", "套票\n總張數", "套票\n總收入", "客戶\n數目", "套票\n總張數", "百份比", "套票\n總收入", "客戶\n數目", "套票\n總張數", "百份比", "操作"]),
                    ...huizongRresultData.map((e) {
                      return tabRowWidgets([
                        Text("${e["selectDate"].toString().replaceAll(" 00:00:00", "").replaceAll(" 23:59:59", "")}"),
                        Text("${e["totalIncome"]}"),
                        Text("${e["totalCount"]}"),
                        Text("${e["taoPiaoCount"]}"),
                        Text("${e["jiaMansJE"]}"),
                        Text("${e["jiaMansCount"]}"),
                        Text("${e["taoPiaoCountJiaMans"]}"),
                        Text("${e["jiaMansPercent"]}"),
                        Text("${e["tpZKJE"]}"),
                        Text("${e["zhuKesCount"]}"),
                        Text("${e["tpZKCount"]}"),
                        Text("${e["zhuKesPercent"]}"),
                        InkWell(
                          onTap: () {
                            // 日期数据
                            String dateTemp = e["selectDate"].toString().replaceAll(" 00:00:00", "").replaceAll(" 23:59:59", "");
                            String s1 = dateTemp.substring(5, 10).replaceAll("-", "/");
                            String s2 = dateTemp.substring(dateTemp.length - 5, dateTemp.length).replaceAll("-", "/");
                            String monthTemp = "'${s1}-${s2}";
                            "${monthTemp}\t"
                                    "${e["totalIncome"]}\t"
                                    "${e["totalCount"]}\t"
                                    "${e["taoPiaoCount"]}\t"
                                    "${e["jiaMansJE"]}\t"
                                    "${e["jiaMansCount"]}\t"
                                    "${e["taoPiaoCountJiaMans"]}\t"
                                    "${e["jiaMansPercent"]}\t"
                                    "${e["tpZKJE"]}\t"
                                    "\t"
                                    "${e["zhuKesCount"]}\t"
                                    "${e["tpZKCount"]}\t"
                                    "${e["zhuKesPercent"]}"
                                .copyValue();
                          },
                          child: Text("Coppy"),
                        ),
                      ]);
                    }),
                  ],
                ),
              ),
            ],
          )
        ],
      ),
    );
  }

  // 客户类型
  String customerType = "all";

  _buildAdjustmentAuditWidget() {
    return Container(
      padding: const EdgeInsets.all(10),
      margin: const EdgeInsets.all(10),
      decoration: BoxDecoration(border: Border.all(color: Colors.deepPurple, width: 3)),
      child: Column(
        children: [
          Text("调整审核", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.red)),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  SizedBox(width: 10),
                  (adjustAuditLoading)
                      ? Center(child: CircularProgressIndicator())
                      : ElevatedButton(
                          onPressed: () {
                            _weekReportBloc?.add(AdjustmentAuditEvent(
                                startDate: adjustAuditStartDate, endDate: adjustAuditEndDate, auditType: auditType[1], auditState: auditState[0], jmCode: []));
                          },
                          child: Text("调整审核数据查询")),
                  SizedBox(width: 10),
                  Container(
                    decoration: BoxDecoration(border: Border.all(color: Colors.blue, width: 3), borderRadius: BorderRadius.circular(5)),
                    child: Row(
                      children: [
                        Text("审核类型"),
                        MenuAnchor(
                            childFocusNode: _auditTypeFocusNode,
                            menuChildren: [
                              ...[
                                [0, "全部"],
                                // [1, "月结调整"],
                                // [2, "独立调整"],
                                // [3, "套票调整"],
                                // [4, "特区费调整"]
                              ].map((e) {
                                return MenuItemButton(
                                  child: Text("${e[1]}"),
                                  onPressed: () {
                                    auditType = e;
                                    setState(() {});
                                  },
                                );
                              })
                            ],
                            builder: (_, controller, child) {
                              return Container(
                                child: auditType == null
                                    ? TextButton(
                                        focusNode: _auditTypeFocusNode,
                                        onPressed: () => (controller.isOpen) ? controller.close() : controller.open(),
                                        child: Text("请选择类型", style: TextStyle(color: Colors.black)))
                                    : TextButton(
                                        focusNode: _auditTypeFocusNode,
                                        onPressed: () => (controller.isOpen) ? controller.close() : controller.open(),
                                        child: Text(auditType[1], style: TextStyle(color: Colors.black))),
                              );
                            }),
                      ],
                    ),
                  ),
                  SizedBox(width: 10),
                  Container(
                    decoration: BoxDecoration(border: Border.all(color: Colors.blue, width: 3), borderRadius: BorderRadius.circular(5)),
                    child: Row(
                      children: [
                        Text("审核状态"),
                        MenuAnchor(
                            childFocusNode: _auditStateFocusNode,
                            menuChildren: [
                              ...[
                                ["全部", "全部"],
                                [0, "未审核"],
                                [1, "已审核"],
                                [2, "已驳回"],
                              ].map((e) {
                                return MenuItemButton(
                                  child: Text("${e[1]}"),
                                  onPressed: () {
                                    auditState = e;
                                    setState(() {});
                                  },
                                );
                              })
                            ],
                            builder: (_, controller, child) {
                              return Container(
                                child: auditState == null
                                    ? TextButton(
                                        focusNode: _auditStateFocusNode,
                                        onPressed: () => (controller.isOpen) ? controller.close() : controller.open(),
                                        child: Text("请选择状态", style: TextStyle(color: Colors.black)))
                                    : TextButton(
                                        focusNode: _auditStateFocusNode,
                                        onPressed: () => (controller.isOpen) ? controller.close() : controller.open(),
                                        child: Text(auditState[1], style: TextStyle(color: Colors.black))),
                              );
                            }),
                      ],
                    ),
                  ),
                  SizedBox(width: 10),
                  Visibility(
                    visible: false,
                    child: Container(
                      decoration: BoxDecoration(border: Border.all(color: Colors.blue, width: 3), borderRadius: BorderRadius.circular(5)),
                      child: Row(
                        children: [
                          Text("客戶类型"),
                          RadioMenuButton(
                              value: customerType,
                              groupValue: "all",
                              onChanged: (value) {
                                customerType = "all";
                                setState(() {});
                              },
                              child: Text("全部")),
                          RadioMenuButton(
                              value: customerType,
                              groupValue: "cxc",
                              onChanged: (value) {
                                customerType = "cxc";
                                setState(() {});
                              },
                              child: Text("CXC直客")),
                          RadioMenuButton(
                              value: customerType,
                              groupValue: "jms",
                              onChanged: (value) {
                                customerType = "jms";
                                setState(() {});
                              },
                              child: Text("加盟商")),
                        ],
                      ),
                    ),
                  ),
                ],
              ),

              CalendarView(
                day: 1,
                onInitDateChanged: (startDateTime, startStr, endDateTime, endStr) {
                  adjustAuditStartDate = "${startStr}";
                  adjustAuditEndDate = "${endStr}";
                },
                onDateStartChanged: (startDateTime, startStr) {
                  print("disMonthFeeStartDate: $startDateTime, $startStr");
                  adjustAuditStartDate = "${startStr}";
                },
                onDateEndChanged: (endDateTime, endStr) {
                  print("disMonthFeeEndDate: $endDateTime, $endStr");
                  adjustAuditEndDate = "${endStr}";
                },
              ),

              ...adjustAuditData.entries.map((element) {
                List<AdjustInvoiceData> adjustmentAuditD20Data = element.value["adjustmentAuditD20Data"] ?? [];
                List<AdjustInvoiceData> adjustmentAuditX20Data = element.value["adjustmentAuditX20Data"] ?? [];
                Map<String, dynamic> invoiceAdjustmentData = element.value["invoiceAdjustmentData"] ?? {};
                return Container(
                  decoration: BoxDecoration(border: Border.all(color: Colors.blue, width: 3)),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Text(
                        "时间范围  ${element.key}",
                        style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold, color: Colors.blue),
                      ),
                      //以下為 $20元或以下的不用填表申請 及 追加收客戶
                      Row(
                        children: [
                          Text("以下為 \$20元以上的数据 (${adjustmentAuditD20Data.length})",
                              style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.red)),
                          ElevatedButton(
                              onPressed: () {
                                StringBuffer sb = StringBuffer();
                                String tempStr = adjustmentAuditD20Data
                                    .map((e) =>
                                        "'${e.bILLCODE}\t${e.cMSERVICENAME}\t${e.cMCODE}\t${e.bCNAME}\t${e.oLDMONEY}\t${e.nOWMONEY}\t${e.adjustedAmount}\t${e.mODIFIERCODE}\t${e.cREATEDATE}\t${e.mODIFYREMARK}\t${e.iYEAR}\t${e.iMONTH}")
                                    .join("\n")
                                    .toString();
                                sb.write(tempStr);
                                sb.toString().copyValue();
                              },
                              child: Text("W"))
                        ],
                      ),
                      if (adjustmentAuditD20Data.isNotEmpty)
                        SizedBox(
                            height: 200,
                            child: SingleChildScrollView(
                                child: Table(border: TableBorder.all(color: Colors.grey, width: 1), children: [
                              tabRows(["運單編號/發票單號", "客戶名称", "客戶編號", "所屬快遞公司", "原金額", "調整金額", "調整後金額", "修改申請人", "申請時間", "申請備註", "年", "月"]),
                              ...adjustmentAuditD20Data.map((e) => tabRows([
                                    "${e.bILLCODE}",
                                    "${e.cMSERVICENAME}",
                                    "${e.cMCODE}",
                                    "${e.bCNAME}",
                                    "${e.oLDMONEY}",
                                    "${e.nOWMONEY}",
                                    "${e.adjustedAmount}",
                                    "${e.mODIFIERCODE}",
                                    "${e.cREATEDATE}",
                                    "${e.mODIFYREMARK}",
                                    "${e.iYEAR}",
                                    "${e.iMONTH}"
                                  ], maxLines: 1)),
                              tabRows([
                                "",
                                "",
                                "",
                                "",
                                "${adjustmentAuditD20Data.fold(0.00, (value, element) => value + double.parse(element.oLDMONEY.toString()))}",
                                "${adjustmentAuditD20Data.fold(0.00, (value, element) => value + double.parse(element.nOWMONEY.toString()))}",
                                "${adjustmentAuditD20Data.fold(0.00, (value, element) => value + double.parse(element.adjustedAmount.toString()))}",
                                "",
                                "",
                                "",
                                "",
                                ""
                              ]),
                            ]))),
                      //以下為 $20元或以下的不用填表申請 及 追加收客戶
                      SizedBox(height: 20),
                      Row(
                        children: [
                          Text("以下為 \$20元或以下的不用填表申請 及 追加收客戶 (${adjustmentAuditX20Data.length})",
                              style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.red)),
                          ElevatedButton(
                              onPressed: () {
                                StringBuffer sb = StringBuffer();
                                String tempStr = adjustmentAuditX20Data
                                        .map(
                                          (e) =>
                                              "\'${e.bILLCODE.toString()}\t${e.cMSERVICENAME}\t${e.cMCODE}\t${e.bCNAME}\t${e.oLDMONEY}\t${e.nOWMONEY}\t${e.adjustedAmount}\t${e.mODIFIERCODE}\t${e.cREATEDATE}\t${e.mODIFYREMARK}\t${e.iYEAR}\t${e.iMONTH}",
                                        )
                                        .join("\n")
                                        .toString() ??
                                    "";
                                sb.write(tempStr);
                                sb.toString().copyValue();
                              },
                              child: Text("W"))
                        ],
                      ),

                      if (adjustmentAuditX20Data.isNotEmpty)
                        SizedBox(
                          height: 200,
                          child: SingleChildScrollView(
                            child: Table(
                              border: TableBorder.all(color: Colors.blue, width: 1),
                              children: [
                                tabRows(["運單編號/發票單號", "客戶名稱", "客戶編號", "所屬快遞公司", "原金額", "調整金額", "調整後金額", "修改申請人", "申請時間", "申請備註", "年", "月"]),
                                ...adjustmentAuditX20Data.map((e) => tabRows([
                                      "${e.bILLCODE}",
                                      "${e.cMSERVICENAME}",
                                      "${e.cMCODE}",
                                      "${e.bCNAME}",
                                      "${e.oLDMONEY}",
                                      "${e.nOWMONEY}",
                                      "${e.adjustedAmount}",
                                      "${e.mODIFIERCODE}",
                                      "${e.cREATEDATE}",
                                      "${e.mODIFYREMARK}",
                                      "${e.iYEAR}",
                                      "${e.iMONTH}",
                                    ], maxLines: 2)),
                                tabRows([
                                  "",
                                  "",
                                  "",
                                  "",
                                  "${adjustmentAuditX20Data.fold(0.00, (value, element) => value + double.parse(element.oLDMONEY.toString()))}",
                                  "${adjustmentAuditX20Data.fold(0.00, (value, element) => value + double.parse(element.nOWMONEY.toString()))}",
                                  "${adjustmentAuditX20Data.fold(0.00, (value, element) => value + double.parse(element.adjustedAmount.toString()))}",
                                  "",
                                  "",
                                  "",
                                  "",
                                  ""
                                ]),
                              ],
                            ),
                          ),
                        ),
                      Row(
                        children: [
                          Text("調整發票每月匯總", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.red)),
                          ElevatedButton(
                              onPressed: () {
                                StringBuffer sb = StringBuffer();
                                sb.write("${element.key.substring(0, 7)}\t");
                                sb.write("${invoiceAdjustmentData["zkOldMonthTotal"]}\t");
                                sb.write("${invoiceAdjustmentData["zkNewMonthTotal"]}\t");
                                sb.write("${invoiceAdjustmentData["zkAdjustedAmount"]}\t");
                                sb.write("${invoiceAdjustmentData["jmOldMonthTotal"]}\t");
                                sb.write("${invoiceAdjustmentData["jmNewMonthTotal"]}\t");
                                sb.write("${invoiceAdjustmentData["jmAdjustedAmount"]}\t");
                                sb.write("${invoiceAdjustmentData["totalOldMonthTotal"]}\t");
                                sb.write("${invoiceAdjustmentData["totalNewMonthTotal"]}\t");
                                sb.write("${invoiceAdjustmentData["totalAdjustedAmount"]}\t");
                                sb.toString().copyValue();
                              },
                              child: Text("W"))
                        ],
                      ),
                      if (invoiceAdjustmentData.isNotEmpty)
                        Table(
                          border: TableBorder.all(color: Colors.blue, width: 1),
                          children: [
                            //月份	原發票銀碼	調整金額	調整後	原發票銀碼	調整金額	調整後	原發票銀碼	調整金額	調整後
                            tabRows(["月份", "原發票銀碼", "調整金額", "調整後", "原發票銀碼", "調整金額", "調整後", "原發票銀碼", "調整金額", "調整後"]),
                            tabRows([
                              "${element.key}",
                              "${invoiceAdjustmentData["zkOldMonthTotal"]}",
                              "${invoiceAdjustmentData["zkNewMonthTotal"]}",
                              "${invoiceAdjustmentData["zkAdjustedAmount"]}",
                              "${invoiceAdjustmentData["jmOldMonthTotal"]}",
                              "${invoiceAdjustmentData["jmNewMonthTotal"]}",
                              "${invoiceAdjustmentData["jmAdjustedAmount"]}",
                              "${invoiceAdjustmentData["totalOldMonthTotal"]}",
                              "${invoiceAdjustmentData["totalNewMonthTotal"]}",
                              "${invoiceAdjustmentData["totalAdjustedAmount"]}",
                            ], maxLines: 3),
                          ],
                        ),
                    ],
                  ),
                );
              }),

              SizedBox(height: 20),
              // 汇总的数据
              Row(
                children: [
                  Text(
                    "汇总的数据。注意汇总会按照整个月计算 （${resultWholeMonthData.entries.length}）",
                    style: TextStyle(fontSize: 28, color: Colors.green, fontWeight: FontWeight.bold),
                  ),
                  ElevatedButton(
                      onPressed: () {
                        StringBuffer sb = StringBuffer();
                        String tempStr = resultWholeMonthData.entries
                            .map((element) {
                              Map<String, dynamic> e = element.value["invoiceAdjustmentData"] ?? {};
                              return "'${element.key.substring(0, 7)}\t${e["zkOldMonthTotal"]}\t${e["zkNewMonthTotal"]}\t${e["zkAdjustedAmount"]}\t${e["jmOldMonthTotal"]}\t${e["jmNewMonthTotal"]}\t${e["jmAdjustedAmount"]}\t${e["totalOldMonthTotal"]}\t${e["totalNewMonthTotal"]}\t${e["totalAdjustedAmount"]}\t";
                            })
                            .join("\n")
                            .toString();
                        sb.write(tempStr);
                        sb.toString().copyValue();
                      },
                      child: Text("W"))
                ],
              ),
              ...resultWholeMonthData.entries.map((element) {
                Map<String, dynamic> invoiceAdjustmentData = element.value["invoiceAdjustmentData"] ?? {};
                return Container(
                  margin: const EdgeInsets.only(top: 5),
                  child: Column(
                    children: [
                      if (invoiceAdjustmentData.isNotEmpty)
                        Table(
                          border: TableBorder.all(color: Colors.brown, width: 1),
                          children: [
                            //月份	原發票銀碼	調整金額	調整後	原發票銀碼	調整金額	調整後	原發票銀碼	調整金額	調整後
                            tabRows(["月份", "原發票銀碼", "調整金額", "調整後", "原發票銀碼", "調整金額", "調整後", "原發票銀碼", "調整金額", "調整後"]),
                            tabRows([
                              "${element.key.substring(0, 7)}",
                              "${invoiceAdjustmentData["zkOldMonthTotal"]}",
                              "${invoiceAdjustmentData["zkNewMonthTotal"]}",
                              "${invoiceAdjustmentData["zkAdjustedAmount"]}",
                              "${invoiceAdjustmentData["jmOldMonthTotal"]}",
                              "${invoiceAdjustmentData["jmNewMonthTotal"]}",
                              "${invoiceAdjustmentData["jmAdjustedAmount"]}",
                              "${invoiceAdjustmentData["totalOldMonthTotal"]}",
                              "${invoiceAdjustmentData["totalNewMonthTotal"]}",
                              "${invoiceAdjustmentData["totalAdjustedAmount"]}",
                            ], fontSize: 12),
                          ],
                        ),
                    ],
                  ),
                );
              }),
            ],
          ),
        ],
      ),
    );
  }
}
